<template>
  <div class="page-container">
    <page_breadcrumb :getKeyMethod="init_table_model" @change="change_table_model" pageOption />
    <ex_super_table_page v-bind="option" ref="SuperTablePage" @selection-change="e => selection = e"
                         @search="searchChange">
    </ex_super_table_page>

    <ex_super_dialog_form ref="disposeDialog" v-bind="dispose_dialog"
                          @afterSubmitSuccess="$refs['SuperTablePage'].reload()">
    </ex_super_dialog_form>
  </div>
</template>

<script>


import superTablePageFunction from '@/mixin/super-table-page-function';
import emitOnFunction from '@/mixin/emit-on-function';
import page_table_model_manage from '@/mixin/page_table_model_manage';
let emitKey = 'platformSync>sync_order_list_halyk'
export default {
  name: "label_halyk_order_list",
  title: 'label_halyk_order_list',
  mixins: [superTablePageFunction, emitOnFunction(emitKey), page_table_model_manage],
  components: {},
  data(){
    return{
      orderStatus: "",
      orderData: {
        waitSubmitCount: null,
        completeSubmitCount: null,
        submitFailCount: null,
        exceptionCount: null,
        canceledCount: null,
      },
      status_map: {
        "WAIT_SUBMIT": 'waitSubmitCount',
        'COMPLETE_SUBMIT': 'completeSubmitCount',
        "SUBMIT_FAIL": 'submitFailCount',
        "EXCEPTION": 'exceptionCount',
        "CANCELED": 'canceledCount',
        "COMPLETE": 'completeCount',
      },
      selection: [],
      option: {
        search: {
          default: { orderStatus: "" },
          model: [
            {
              key: 'orderStatus', label: 'label_status', itemClass: "w_fill",
              render: (h, { data }) => {
                let enums = this.$enumOptions['SrmOrderStatusEnum']
                const list = enums.map(it => (
                  <el-radio-button key={it} label={it}>
                    {this.$enumShow(it, 'SrmOrderStatusEnum')}
                    {this.status_map[it] && this.orderData[this.status_map[it]] ? `(${this.orderData[this.status_map[it]]})` : "(0)"}
                  </el-radio-button>
                ))
                return (<el-radio-group value={data.orderStatus}
                                        onInput={e => {
                                          this.orderStatus = e
                                          this.$set(data, 'orderStatus', e)
                                          this.$refs.SuperTablePage.loadDataForSearch()
                                        }}>
                    <el-radio-button key="" label="">
                      {this.$tt("label_all")}
                    </el-radio-button>
                    {list}
                  </el-radio-group>
                )
              }
            },
            { key: 'orderCode', label: 'label_platform_code', },
            { key: 'shipmentTrackingNumber', label: 'label_waybill_delivery_number', },
            {
              label: "label_create_time", key: 'createTimeStart', type: 'date-picker',
              placeholder: "label_create_start_time", attrs: { type: 'datetime' },
              on: { change: (e) => this.createTimeStart = e },
              pickerOptions: {
                disabledDate: (date) => {
                  if (this.createTimeEnd) {
                    return this.createTimeEnd < date.getTime()
                  }
                  return false
                }
              }

            },
            {
              label: "~", key: 'createTimeEnd', type: 'date-picker',
              placeholder: "label_create_end_time", attrs: { type: 'datetime' },
              on: { change: (e) => this.createTimeEnd = e },
              'pickerOptions': {
                disabledDate: (date) => {
                  if (this.createTimeStart) {
                    return this.createTimeStart > date.getTime()
                  }
                  return false
                }
              }
            },
          ],
        },


        table: {
          url: "/srm-api/platform/HalykOrderRpc/selectPage.json",
          model: this.init_table_model(),
        },
      },
      dispose_dialog: {
        customClass: 'dialog_auto',
        submitUrl: '/srm-api/platform/HalykOrderRpc/saveOrUpdate.json',
        submitDataHandle: (data) => {
          data.id = data.id
          data.shipmentTrackingNumber = data.shipmentTrackingNumber
          return data
        },
        form: {
          itemClass: "form_item_default", inputClass: "form_input_default",
          formClass: "form_default_col2 flex_row_wrap",
          default: {},
          model: [
            {key: 'code', label: 'label_platform_code', formType: 'text'},
            {key: 'shipmentTrackingNumber', label: 'label_waybill_delivery_number', type: 'input'}
          ],
        }
      },
    }
  },
  methods: {
    clickDetail(row) {
      this.$router.push({
        path: '/page/oms/platformSync/sync_order_detail_halyk', query: { id: row.id, }
      })
    },
    searchChange() {
      this.$ajax({
        url: "/srm-api/platform/HalykOrderRpc/selectOrderStatCount.json",
        method: 'post',
        data: this.$refs.SuperTablePage.getSearchFormData(),
        success: (res) => {
          this.orderData = res.data
        }
      })
    },
    option_table_model() {
      return [
        { type: 'selection', clickToggle: true, keyGroup: 'label_table_operate' },
        // {
        //   type: 'expandDesc', 'width': 100,
        //   expandDesc: {
        //     ...this.$defaultDescAttrs,
        //     model: [],
        //   },
        // },
        { key: 'code', label: 'label_platform_code','width': 120, 'show-overflow-tooltip': true, },
        {
          key: 'customerName', label: 'label_customer_info', 'width': 120, 'show-overflow-tooltip': true,
          formatter: (r, c, v, i) => this.$formatNameCode(v, r.customerCode)
        },
        {
          key: 'totalPrice', label: '总价格', 'width': 110, 'show-overflow-tooltip': true,
          formatter: (r, c, v, i) => {
            return r.totalPrice + '[' + r.currencyType + '] '
          }
        },
        {
          key: 'deliveryCost', label: '运费', 'width': 110, 'show-overflow-tooltip': true,
          formatter: (r, c, v, i) => {
            return r.deliveryCost + '[' + r.currencyType + '] '
          }
        },
        {
          key: 'deliveryMode', label: '交货方式', 'width': 110, 'show-overflow-tooltip': true,
        },
        {
          key: 'deliveryType', label: '交货类型', 'width': 110, 'show-overflow-tooltip': true,
        },
        {
          key: 'status', label: '平台订单状态', 'width': 110, 'show-overflow-tooltip': true,
        },
        {
          key: 'paymentMode', label: '支付方式', 'width': 110, 'show-overflow-tooltip': true,
        },

        { key: 'deliveryAddressFormattedAddress', label: 'label_consignee_address', 'width': 110, 'show-overflow-tooltip': true, },

        { key: 'customerFirstName', label: '买家名称', 'width': 110, 'show-overflow-tooltip': true,
          formatter: (r, c, v, i) => {
            return r.customerFirstName + ' ' + r.customerLastName
          }},
        { key: 'customerCellPhone', label: '买家电话', 'width': 110, 'show-overflow-tooltip': true, },

        {
          key: 'orderStatus', label: 'label_status', 'width': 120, 'show-overflow-tooltip': true,
          formatter: (r, c, v, i) => this.$enumShow(v, "SrmOrderStatusEnum")
        },
        { key: 'shipmentTrackingNumber', label: 'label_waybill_delivery_number', 'width': 110, 'show-overflow-tooltip': true, },
        {
          key: 'exceptionMsg', label: 'label_exception_info', 'width': 120,
          render: (h, { row, column }) => {
            const code = row[column.property]
            if (!code) return ""
            return (<text_extra_tooltip_operate
              value={code} ellipsis
              data_type={column.property} data_id={row.id}
            />)
          },
        },
        { key: 'creationDate', label: 'label_create_time', formatter: (r, c, v, i) => this.$dateFormat(v) },
        {
          type: 'operate', width: 220,
          fixed: 'right',
          operate: [

            { label: 'label_view_detail', click: (row) => this.clickDetail(row) },
            {
              label: '绑定发货单', click: (row) => {
                this['$refs']['disposeDialog'].showNew({title:'绑定发货单',data: _.clone(row)})
              }
            },
          ]
        }
      ]
    },
  }
}
</script>


<style scoped>

</style>
